def f(n):
    try:
        if n > 30:
            return n * n + 5 * n + 4
        elif n % 2 == 0:
            return f(n+1)+ 3 * f(n+4)
        else:
            return 2 * f(n+2) + f(n+5)
    except:
        return None
s = 0
for i in range(1001):
    e = f(i)
    if e != None and sum(list(map(int,list(str(e))))) == 27:
        s += 1
print(s)

